package com.sleepcamel.resteasyConfigurator.model.dbwizard;

import java.beans.PropertyChangeListener;
import java.io.File;


import com.sleepcamel.exporter.util.JdbcUtils;
import com.sleepcamel.rest.domain.BaseBean;
import com.sleepcamel.rest.domain.util.RestConstants;

public class FirstPageModel extends BaseBean implements IWizardPageModel {

	private JdbcUtils jdbcUtils;
	private File outputDirectory;
	private String projectName = RestConstants.EXAMPLE_PROJECT_NAME;
	private String packageName = RestConstants.EXAMPLE_PACKAGE_NAME;

	public FirstPageModel() {
		jdbcUtils = new JdbcUtils();
	}
	
	@Override
	public void addPropertyChangeListener(PropertyChangeListener listener) {
		super.addPropertyChangeListener(listener);
		jdbcUtils.addPropertyChangeListener(listener);
	}

	@Override
	public boolean isComplete() {
		return !jdbcUtils.getUserName().isEmpty() && !jdbcUtils.getPassword().isEmpty()
			&& !jdbcUtils.getUrl().isEmpty() && !jdbcUtils.getDriver().isEmpty()
			&& outputDirectory != null
			&& projectName != null && !projectName.isEmpty() 
			&& packageName != null && !packageName.isEmpty();
	}

	public JdbcUtils getJdbcUtils() {
		return jdbcUtils;
	}

	public void setJdbcUtils(JdbcUtils jdbcUtils) {
		this.jdbcUtils = jdbcUtils;
	}

	public File getOutputDirectory() {
		return outputDirectory;
	}

	public void setOutputDirectory(File outputDirectory) {
		firePropertyChange("outputDirectory", this.outputDirectory, this.outputDirectory = outputDirectory);
	}

	public String getProjectName() {
		return projectName;
	}

	public void setProjectName(String projectName) {
		firePropertyChange("projectName", this.projectName, this.projectName = projectName);
	}

	public String getPackageName() {
		return packageName;
	}

	public void setPackageName(String packageName) {
		firePropertyChange("packageName", this.packageName, this.packageName = packageName);
	}

}
